﻿using Core.Common;
using Core.DTO;
using IServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.Controllers
{

    [ApiController]
    [Route("api/[Controller]/[action]")]
   
    public class HomeController : ControllerBase
    {
        // GET: HomeController

        IAdvertisementServices _advertisementServices = null;
        IBlogArticleServices _IBlogArticleServices = null;
        IRedisBasketRepository _RedisBasketRepository = null;

        public HomeController(IAdvertisementServices AdvertisementServices,IBlogArticleServices IBlogArticleServices, IRedisBasketRepository IRedisBasketRepository)
        {
            _advertisementServices = AdvertisementServices;
            _IBlogArticleServices = IBlogArticleServices;
            _RedisBasketRepository = IRedisBasketRepository;
           // advertisementServices = new AdvertisementServices();
        }
        /// <summary>
        /// 获取jwt
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet]
        public async Task<object> GetJwtStr(string UserName, string pass)
        {
            TokenModelJwt tokenModel = new TokenModelJwt { Uid = 1, Role = "Admin" };
            var jwtStr = JwtHelper.IssueJwt(tokenModel);//登录，获取到一定规则的 Token 令牌
            var suc = true;
            return Ok( new
            {
                success = suc,
                token = jwtStr
            });


        }



     //  [Authorize(Policy = "SystemOrAdmin")]
         /// <summary>
         /// 测试接口
         /// </summary>
         /// <returns></returns>
        [HttpGet]
        public  async Task<string> Get()
        {

          var s= await _advertisementServices.Query();


            return "";

        }



        [HttpGet]
        public async Task<List<BlogArticle>> Getblog()
        {
            //  string sb=   Appsettings.app(new string[] { "Redis", "ConnectionString"});
           // _RedisBasketRepository.Set("10", 10, 1);


            List<BlogArticle> blogArticleList = new List<BlogArticle>();
            blogArticleList = await _IBlogArticleServices.Get();
          
           

            return blogArticleList;

        }

        [HttpGet]
        public async Task<BlogViewModels> Getdetail()
        {
            BlogViewModels sss=await _IBlogArticleServices.Getdetail(1);
            return sss;

        }


            // GET: HomeController/Details/5


            // GET: HomeController/Create


            // POST: HomeController/Create



            // POST: HomeController/Edit/5

        }
}
